/**
 * 历史查询控制器
 */
import $_fn from '~plugins'
import './index.less'
import JSEncrypts from '~plugins/lib/js/jsencrypt.js'
export default ['$scope','$rootScope','$location','$ui','http','$state',function($scope,$rootScope,$location,$ui,http,$state) {
    $scope.$_fn = $_fn
	//四级按钮
	$scope.tabMenu = $_fn.getCurrMenu($location.path())
    console.log($scope.tabMenu)
    $scope.subMenu = $scope.tabMenu.children[0].children
    console.log($scope.subMenu)
	console.log('查询历史')
	//四级按钮页面跳转方法
	$scope.operation = function (path,item) {
		console.log('111')
        var _path = path.split('@')
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1], item)
        }
        if(_path[0] == 'alert'){
            $ui.modal({content:"<"+_path[1]+" params="+params+"></"+_path[1]+">"})
        }
   }
	var encrypt1 = new JSEncrypts.JSEncrypt();//公钥对象
	var encrypt2 = new JSEncrypts.JSEncrypt();//私钥对象
	//公钥
	encrypt1.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCo9yyyvSUdMIu+Q3FniJuzFSfYyOc0UHZ/JGyWqwTlIgWxyAm6AcyRTzP//L6JdQ6+u8QSRWTmWW+dMSeGm0tYVAobGvTGG1eIduhE1RMqGYDbHzlCzTgkfvMIEpRncjzQYMDtlXH+i+sVeIEgM+eJnnCgRte5vicHKKkFmlg8LQIDAQAB");
	//私钥
	encrypt2.setPrivateKey('MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKfrKjZyCf8tI52u6LEwLMgmOKdNhqjVrNhnL3c9+pU0KRYKQrmDDf7R/jI7ZTI92luTUFw4PF1AJJgkgMRWQveZryD465lLX2M+Y6QasMk/VOJtdU+iZ1TQOeCzS//Hr3GpRYHUL6Q2oUsoDRgP+bvi13ypS8BnlvhxCxyCZi2VAgMBAAECgYBurd2kB2S5ckpAe/JaIBPUVQUQmVQB4t1Lwi+SHCMXx0qxgU/bsRs/c7Bl8apRBF3x8FaOgm6fVFEKizzorKb0M8MiHhp5FjLmg5+lPMgylaYSBQbEckFGBtPx5LXG+LdRU+VIi+RJtye4xzk2URSOk6iBBuykWknZpBlrcJ9e4QJBAOck0+PaZUjbaAf2y4e6i21OPkyqkbf58R0rmva9WVcXX3rgQtj5qXJqcB501NlLaz2fVb1cwcoxqyVCM63OGckCQQC5+c5MexsOU6pi15YJWw1fnrsOeA+Lg0MLcn6N7MGgfrG2Bygobgb6X1tKKAbAWbl5n+4UXvWQ0yKaXiAkBRttAkAFxgi450qiYECf+k0pLcKvz0WFGrmbE9Yu+Vjckuw5Xa8X3aQt0UanQftc92QdrWGXX3R/z2JTz5vLyXSLAdvpAkBfz11Ds4xNxjaac1x9d2YdY+YUXzAK/NW2eQbP0TAzofGlyGwc4ApCRIwAWTyZLeBK02TRI9a5BLzn8CP4ypTFAkEAq4tAs14vKDlR97V85Tq5mUXoAjEO2I2rFX+44uqkXlESkhStW2ML93j9ziU8HMhoETQ287Ze7hTYiLv4h54E1g==')

	//参数加密
    $scope.jiaMi=function(param){
    	for(name in param){
			param[name]=encrypt1.encrypt(param[name]+'')
		}
    }
    $scope.qiYeMa=function(){
		http.post('getCompanyCredit.do',{},function (data) {
            if(data.errcode > 0){
                $scope.$apply(function () {
                	$scope.param8=data.data
                	$scope.getDada()
                  //  $scope.param3.domainName= 'http://192.168.1.11';  
                })
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
		})
	}
	$scope.qiYeMa()
	//初始化对象
	$scope.param2={
		pageNum:1,
		positionId:-1,
		departmentId:-1,
		locked:-1
	}
	$scope.param1={}
	//获取数据的函数
	$scope.param2={}
    $scope.getDada = function(){
        //$scope.param.pageNum = page
       $scope.param2.cid=$scope.param8.company_id;
      // $scope.param2.cid="1";
        $scope.param2.code=$scope.param8.code;
        $scope.jiaMi($scope.param2)
        http.post1('getHistorylist',$scope.param2,function (data) {
        	console.log(data)
            if(data.errcode == 0){
                //列表无数据
                if(data.list.length === 0){
                    $scope.isData = true
                    $scope.$apply()
                }
                $scope.$apply(function () {
                   $scope.param1=data
                   $scope.param1.list=data.list
                })
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
            $scope.$apply()
        })
    }
	
    $scope.select = [{name:'以租代购',value:1},{name:'信贷方式',value:2}]
    $scope.popup = {
        opened: true
    }
    $scope.open = function () {
        $scope.popup.opened = !$scope.popup.opened
    }
}]
